package ru.common.hibernate;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

/**
 * @author bogaser
 */
public class ActionCallback<T> implements HibernateCallback {

    private final HibernateAction<? extends T>[] actions;

    private T result;

    public ActionCallback(HibernateAction<? extends T>... actions) {
        this.actions = actions;
    }

    public T getResult() {
        return result;
    }

    @Override
    public Void doInHibernate(Session session) throws HibernateException {
        for (HibernateAction<? extends T> action : actions) {
            result = action.execute(session);
        }
        return null;
    }

}
